package com.lmy.springCloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RefreshScope   //springCloud原生注解，实现了配置数据的自动刷新
public class NacosConfigClientController {

    /*
        1.client会拉取 nacos server 中 dataId为 e-commerce-nacos-config-client-dev.yaml 的数据
            config:
                ip: "122.22.22.22"
                name: "lmy"
        2. ${config.ip} 表示会将 ip赋给configIp属性
        3. 这里@Value中的值不能乱写，要根据配置文件来，否则服务无法正常启动
     */
    @Value("${config.ip}")
    private String configIp;

    @Value("${config.name}")
    private String configName;

    @RequestMapping(value = "/nacos/config/ip")
    public String getConfigIp() {
        return configIp;
    }

    @RequestMapping(value = "/nacos/config/name")
    public String getConfigName() {
        return configName;
    }
}
